<script setup>
import { ref,onMounted } from 'vue'
import { queryUserAll } from '@/api/user'

//分页数据显示
const getUserAll =async ()=>{
  const result = await queryUserAll(page.value,pageSize.value,userDate.value.name,userDate.value.gender)
  userInfo.value = result.data.rows
  total.value = result.data.total
}

onMounted(()=>{
  getUserAll()
})

//定义表单绑定的数据
const userDate = ref({name:'',gender:''})
//定义清空的点击事件
const clear=()=>{
  userDate.value={name:'',gender:''}
  getUserAll()
}

//定义表格显示数据
const userInfo = ref([])

//定义分页的变量
const page = ref(1)
const pageSize = ref(5)
const total = ref(0)

//定义分页的点击事件
const handleSizeChange = (val) => {
  page.value = 1
  getUserAll()
}
const handleCurrentChange = (val) => {
  getUserAll()
}
</script>

<template>
<div>
    <el-form :inline="true" :model="userDate" class="demo-form-inline">
    <el-form-item label="姓名">
      <el-input v-model="userDate.name" placeholder="请输入姓名" />
    </el-form-item>
    <el-form-item label="性别">
      <el-select v-model="userDate.gender" placeholder="请选择" style="width: 200px;" >
        <el-option label="男" value="1" />
        <el-option label="女" value="2" />
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="getUserAll">查询</el-button>
      <el-button type="info" @click="clear">清空</el-button>
    </el-form-item>
  </el-form>
</div>

<div>
  <el-table :data="userInfo" border style="width: 100%" >
    <el-table-column prop="name" label="姓名" width="180" align="center" />
    <el-table-column prop="gender" label="性别" width="180" align="center">
      <template #default="scope">
        {{ scope.row.gender === 1 ? '男' : '女' }}
      </template>
    </el-table-column>
    <el-table-column prop="createTime" label="创建时间" width="180" align="center"/>
  </el-table>
</div>

<div>
     <el-pagination
      v-model:current-page="page"
      v-model:page-size="pageSize"
      :page-sizes="[5, 10, 15, 20]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
</div>
</template>

<style scoped>

</style>